<?php echo $this->render('link/header.phtml') ?>
<?php $gridId=uniqid(); ?>
//常用变量初始化
var menuDelUrl=baseUrl+"/link/serversite/type/del";
var menuEditUrl=baseUrl+"/link/serversite/type/edit";
var module="site";
var gridTitle="数据导入<a style='float:right;padding-right:30px' href='"+baseUrl+"/public/uploads/export.csv'>示例文件</a>";
var dataId="site_id";
Ext.form.Field.prototype.msgTarget = 'side';
linktype_combo_store.load();   
site_combo_store.load();
var linktype_combo=new Ext.form.ComboBox({
										 fieldLabel:'链接类型',
										 store:linktype_combo_store,										
        								displayField:'linktype_name',
        								valueField :'linktype_id',
										hiddenName:"linktype_id",
        								typeAhead:true,
        								mode:'local',
        								triggerAction:'all',
                                        editable:false,  
        								selectOnFocus:true,
                                        emptyText:"请选择"     
										 });                                       

var site_combo=new Ext.form.ComboBox({
										width:80,
										 fieldLabel:'站点类型',
										 store:site_combo_store,										
        								displayField:'site_type',
        								valueField :'site_id',
										hiddenName:"site_id",
        								typeAhead:true,
        								mode:'local',
        								triggerAction:'all',
                                        editable:false,  
        								selectOnFocus:true
										 });                                                                                
var import_add=new Ext.FormPanel({
	frame:true,
    title:gridTitle,
    labelWidth:100,
    autoWidht:true,
    autoHeight:true,    
    bodyStyle:'padding:0 0 0 0;',    
    fileUpload: true,
    items:[
    	  linktype_combo,
          site_combo,
    	  new Ext.form.FileUploadField({
          id:'import_file',
          name:'import_file',
          xtype:'FileUploadField',
          fieldLabel:'选择文件：',
          buttonText:'浏览文件...',
          width:300
          })
    ],
    buttons:[
    {
    id:'submit',
    text:'提交',
    type:'submit',
    iconCls:'icn-control',
    handler:function(){
    var fileName=Ext.getCmp('import_file').getValue();
    if(fileName==''){
    	Ext.MessageBox.alert('提示',"没有选择文件");
        return false;
    }
    var pos=fileName.lastIndexOf(".");
    var fileType=fileName.substring(pos,fileName.length).toLowerCase();
    if(fileType!=".csv"){
    	Ext.MessageBox.alert('提示',"文件类型必须为csv文件!"+"不支持"+fileType+"格式");
        return false;
    }
    if(import_add.getForm().isValid()){
    import_add.getForm().submit({
    waitTitle:'提示',
    waitMsg:'请稍等',
    url:baseUrl+'/link/import/',
    success:function(form,action){
    	var _message=Ext.util.JSON.decode(action.response.responseText);
		Ext.MessageBox.alert('提示',_message.msg);
    },
    failure:function(form,action){
    	var _message=Ext.util.JSON.decode(action.response.responseText);
        Ext.MessageBox.alert('提示',_message.msg);
    }
    });
    }   
    }},{
    text:'退出',
    handler:function(){
    Ext.getCmp('content').getActiveTab().remove();
    }
    }
    ]
});



var auto=new Ext.Panel({
	layout: 'accordion',
    renderTo:'grid_<?=$gridId?>',
    items:[import_add]
});

});
</script>
<body style="width:98%;height:100%">
<div id='grid_<?=$gridId?>'></div>
</body>
</html>
